﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ArunimaErp.Domain;
using ArunimaErp.Models;

namespace ArunimaErp.Controllers
{ 
    public class CostSheetController : Controller
    {
        private arunimaEntities db = new arunimaEntities();

        //
        // GET: /CostSheet/Create

        public ActionResult Create(int id)
        {
            ViewBag.PoStyleId = db.postyle.SingleOrDefault(x => x.PoStyleId == id).PoStyleId;
            return View();
        } 

        //
        // POST: /CostSheet/Create

        [HttpPost]
        public ActionResult Create(costsheet costsheet)
        {
            if (ModelState.IsValid)
            {
                db.costsheet.Add(costsheet);
                db.SaveChanges();

                return Json(JsonResponseFactory.SuccessResponse(costsheet), JsonRequestBehavior.DenyGet);
            }

            ViewBag.PoStyleId = new SelectList(db.postyle, "PoStyleId", "PoNo", costsheet.PoStyleId);
            return View(costsheet);
        }
        
        //
        // GET: /CostSheet/Edit/5
 
        public ActionResult Edit(int id)
        {
            costsheet costsheet = db.costsheet.SingleOrDefault(x => x.PoStyleId == id);
            
            return View(costsheet);
        }

        //
        // POST: /CostSheet/Edit/5

        [HttpPost]
        public ActionResult Edit(costsheet costsheet)
        {
            if (ModelState.IsValid)
            {
                db.Entry(costsheet).State = EntityState.Modified;
                db.SaveChanges();
                return Json(JsonResponseFactory.SuccessResponse(costsheet), JsonRequestBehavior.DenyGet);
            }
            ViewBag.PoStyleId = new SelectList(db.postyle, "PoStyleId", "PoNo", costsheet.PoStyleId);
            return View(costsheet);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}